{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c6429310",
   "metadata": {},
   "outputs": [],
   "source": [
    "from pandas import read_excel, set_option\n",
    "\n",
    "set_option(\"display.max_columns\", 10)\n",
    "df = read_excel(r\"./电动1.xls\")\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8447ff64",
   "metadata": {},
   "source": [
    "1. 输出前三条记录"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dde7424c",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.head(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ecf904de",
   "metadata": {},
   "outputs": [],
   "source": [
    "df[:3]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ae95b759",
   "metadata": {},
   "source": [
    "2. 输出最后三条记录"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ec27e6e7",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.tail(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "69af4e4f",
   "metadata": {},
   "outputs": [],
   "source": [
    "df[-3:]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f6fce2b7",
   "metadata": {},
   "source": [
    "3. 输出最后三条记录的前三列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0f5beae7",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.iloc[-3:, :3]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c8576062",
   "metadata": {},
   "source": [
    "4. 输出最后三条记录的所有大学英语成绩"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "95808ec7",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.tail(3)[[\"大学英语Ⅰ\", \"大学英语Ⅱ\", \"大学英语Ⅲ\"]]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7cba9302",
   "metadata": {},
   "source": [
    "5. 输出第一条记录（从1开始算）的C语言程序设计成绩"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3f386f45",
   "metadata": {},
   "outputs": [],
   "source": [
    "df[:1][\"C语言程序设计\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "049b2276",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.loc[1, \"C语言程序设计\"] # loc是根据位置location来具体取值的，iloc是用index"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d4ab8147",
   "metadata": {},
   "source": [
    "6. 输出所有没有选修肚皮舞的记录"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6f26fa17",
   "metadata": {},
   "outputs": [],
   "source": [
    "# df['肚皮舞'] # 选取肚皮舞这一列\n",
    "df[df['肚皮舞'].isna()] # 肚皮舞是空的那些列"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c36fbb60",
   "metadata": {},
   "source": [
    "7. 输出C语言程序设计在90分以上的记录"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "82bee81d",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "'>' not supported between instances of 'str' and 'int'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-12-9cad3a53d8ff>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mdf\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'C语言程序设计'\u001b[0m \u001b[1;33m>\u001b[0m \u001b[1;36m90\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m: '>' not supported between instances of 'str' and 'int'"
     ]
    }
   ],
   "source": [
    "df['C语言程序设计' > 90]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
